﻿using System;
using System.Text;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;

namespace mfLogger
{
    /// <summary>
    /// write the received messages on Micorsoft.SPOT.Debug.Print
    /// </summary>
    /// <remarks>should just be used in debugging cases</remarks>
    public class mfDebugAppender : ILoggerAppender
    {
        #region CTOR

        public mfDebugAppender()
        {
            Name = this.GetType().Name;
            IsEnabled = true;
            Level = mfLogger.Instance.Level;
        }

        public mfDebugAppender(string name)
        {
            Name =name;
            IsEnabled = true;
            Level = mfLogger.Instance.Level;
        }

        #endregion

        #region ILogger
        public string Name
        {
            get;
            set;
        }

        public bool IsEnabled { get; set; }

        public enumLogMessageLevel Level
        {
            get;
            set;
        }

        public void Debug(string text)
        {
            HandleMessage(new mfLogMessage(enumLogMessageLevel.Debug, text));
        }

        public void Log(mfLogMessage msg)
        {
            HandleMessage(msg);
        }

        public void Info(string text)
        {
            HandleMessage(new mfLogMessage(text));
        }

        public void Warning(string text)
        {
            HandleMessage(new mfLogMessage(enumLogMessageLevel.Warning, text));
        }

        public void Error(Exception ex)
        {
            HandleMessage(new mfLogMessage(ex));
        }

        public void Error(string text)
        {
            HandleMessage(new mfLogMessage(enumLogMessageLevel.Error, text));
        }

        public void HandleMessage(mfLogMessage msg)
        {
            if (msg.Level >= Level)
            {
                Microsoft.SPOT.Debug.Print(msg.ToString());
            }
        }
        #endregion

    }
}